#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys

def cfd():
	"""Get the directory for the current script file."""
	path = sys.path[0]
	if os.path.isfile(path):
		path = os.path.dirname(path)
	return path

if __name__ == '__main__':
	args = sys.argv
	
	if len(args) != 2:
		print 'ERRO: need argument (fileName)'
                exit()

	#outputPath = cfd()
	inputFile = args[1]

	try:
		inputFile = open(args[1],'rb')
		baseName = os.path.basename(args[1])
		outputFile = open(cfd() + '/src/' + baseName + '.properties','w')
		count = 0
		try:
			for line in inputFile:
				line = line.replace('\r','').replace('\n','')
				datas = line.split(',')
				if len(datas) == 4:
					outputFile.write(baseName + '.' + str(count) + ".name=" + datas[0] + "\n")
					outputFile.write(baseName + '.' + str(count) + ".width=" + datas[1] + "\n")
					outputFile.write(baseName + '.' + str(count) + ".height=" + datas[2] + "\n")
					outputFile.write(baseName + '.' + str(count) + ".weight=" + datas[3] + "\n")
					outputFile.write("\n")
				count = count + 1
			outputFile.write("count="+str(count) + "\n")
			if count > 18:
				count = 18
			outputFile.write("limit.count="+str(count) + "\n")
			
		finally:
			inputFile.close()
			outputFile.close()
	except IOError:
		print 'Error: can not find the file!'

	

